<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\api\validate;

use think\Validate;

/**
 * API用户验证器
 */
class User extends Validate
{
    // 验证规则
    protected $rule = [
        'code' => 'require|max:255',
        'invite_code' => 'max:32',
        'user_id' => 'require|integer|gt:0',
        'nickname' => 'max:50',
        'avatar' => 'max:255',
        'avatar_id' => 'integer|egt:0',
        'user_token' => 'require',
        'product_id' => 'require|integer|gt:0',
        'price' => 'require|float|gt:0',
        'page' => 'integer|egt:1',
        'limit' => 'integer|between:1,100',
    ];

    // 验证消息
    protected $message = [
        'code.require' => '微信授权码不能为空',
        'code.max' => '微信授权码格式错误',
        'invite_code.max' => '邀请码格式错误',
        'user_id.require' => '用户ID不能为空',
        'user_id.integer' => '用户ID必须为整数',
        'user_id.gt' => '用户ID必须大于0',
        'nickname.max' => '昵称长度不能超过50个字符',
        'avatar.max' => '头像地址长度不能超过255个字符',
        'avatar_id.integer' => '头像ID必须为整数',
        'avatar_id.egt' => '头像ID必须大于等于0',
        'user_token.require' => '用户token不能为空',
        'product_id.require' => '商品ID不能为空',
        'product_id.integer' => '商品ID必须为整数',
        'product_id.gt' => '商品ID必须大于0',
        'price.require' => '价格不能为空',
        'price.float' => '价格必须为数字',
        'price.gt' => '价格必须大于0',
        'page.integer' => '页码必须为整数',
        'page.egt' => '页码必须大于等于1',
        'limit.integer' => '每页数量必须为整数',
        'limit.between' => '每页数量必须在1-100之间',
    ];

    // 验证场景
    protected $scene = [
        'wechat_login' => ['code'],
        'get_info' => ['user_token'],
        'update_info' => ['user_token', 'nickname', 'avatar', 'avatar_id'],
        'follow' => ['user_token', 'product_id'],
        'unfollow' => ['user_token', 'product_id'],
        'price_alert' => ['user_token', 'product_id', 'price'],
        'follow_list' => ['user_token', 'page', 'limit'],
        'invite_stats' => ['user_token'],
        'invite_records' => ['user_token', 'page', 'limit'],
        'check_status' => ['user_token'],
    ];
}